import got from "got";
import qs from "qs";
import { readFileByType } from "./util";
import { processRedness } from "./processRedness";

const prefixUrl = process.env.ICAN_PREFIXURL;
const showRednessUrl = process.env.ICAN_SHOW_REDNESS;
const token = readFileByType('access_token')
const user_id = readFileByType('user_id')

const showRedness = async () => {
  const headers = {
    authorization: `Bearer ${token}`
  }
  const formData = {
    // 组织2个人1
    type: 1,
    // id
    relationId: user_id
  }
  const params = qs.stringify(formData);
  const postUrl = `${prefixUrl}${showRednessUrl}?${params}`;
  try {
    const res = await got.get(postUrl, {
      headers,
    });
    const jsonData = JSON.parse(res!.body)
    processRedness(jsonData.data)
  } catch (error) {
    console.error(error);
  }
}
export {
  showRedness
}